// pages/tongji/tongji.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
      startime:"请选择开始时间",
      endtime:'请选择结束时间',
      satype:'请选择类型',
      said:0,
      yiyuan_id:2,
      data:[],
    array: ['已预约', '未到', '已到', '全部'],
    objectArray: [
      {
        id: 0,
        name: '已预约'
      },
      {
        id: 1,
        name: '未到'
      },
      {
        id: 2,
        name: '已到'
      },
      {
        id: 3,
        name: '全部'
      }
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      yiyuan_id: options.id
    });
    wx.setNavigationBarTitle({
      title: '数据统计'
    })
  },
  changeDate:function(e){
    this.setData({ 
      startime: e.detail.value
    }); 
    this.getdata();
  },
  changeDateend: function (e) {
    this.setData({
      endtime: e.detail.value
    });
    this.getdata();
  },
  bindPickerChange:function(e){
    this.setData({
      satype: this.data.objectArray[e.detail.value]['name'],
      said: this.data.objectArray[e.detail.value]['id'],
    });
    this.getdata();
  },
  //获取数据
  getdata:function(){
    var yiyuan_id = this.data.yiyuan_id;
    var startime = this.data.startime;
    var endtime = this.data.endtime;
    var satype = this.data.satype;
    var said = this.data.said;
    var that = this;
    if (startime == '请选择开始时间' || endtime == '请选择结束时间' || satype == '请选择类型'){
      return;
    }
    wx.showToast({
      title: '获取成功',
      icon: 'success',
      duration: 2000
    })
    var url = app.globalData.localUrl + 'tongji';
    wx.request({
      url: url,
      data: {
        id: yiyuan_id,
        startime:startime,
        endtime:endtime,
        stype: said,
        user_id: wx.getStorageSync('userInfo').id
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (a) {
        if (a.data.code == 1) {
          console.log(a);
          that.setData({
              data:a.data.data
          });
        } else {
          wx.showToast({
            title: '暂无数据',
            icon: 'loading',
            duration: 2000
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})